import axios from 'axios';
import fileDownload from 'js-file-download';
export const getdate=(val)=>{
	if(!val)return '';
    var unixtimestamp = new Date(val*1000);
    var year = 1900 + unixtimestamp.getYear();
    var month = "0" + (unixtimestamp.getMonth() + 1);
    var date = "0" + unixtimestamp.getDate();
    var hour = "0" + unixtimestamp.getHours();
    var minute = "0" + unixtimestamp.getMinutes();
    var second = "0" + unixtimestamp.getSeconds();
    return year + "-" + month.substring(month.length-2, month.length)  + "-" + date.substring(date.length-2, date.length)

};
export const getdate1=(val)=>{
	if(!val)return '';
    var unixtimestamp = new Date(val*1000);
    var year = 1900 + unixtimestamp.getYear();
    var month = "0" + (unixtimestamp.getMonth() + 1);
    var date = "0" + unixtimestamp.getDate();
    var hour = "0" + unixtimestamp.getHours();
    var minute = "0" + unixtimestamp.getMinutes();
    var second = "0" + unixtimestamp.getSeconds();
    return year + "-" + month.substring(month.length-2, month.length)  + "-" + date.substring(date.length-2, date.length)+' '+hour.substring(hour.length-2, hour.length)+':'+minute.substring(minute.length-2, minute.length)+':'+second.substring(second.length-2, second.length)
};

export const formDate=()=>{
    let date = new Date(),
    Y = date.getFullYear(),
    M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1),
    D = date.getDate()>9?date.getDate():'0'+date.getDate();
    return Y+'-'+M+'-'+D;
}

export const formDateTime=()=>{
    let date = new Date(),
        Y = date.getFullYear(),
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1),
        D = date.getDate()>9?date.getDate():'0'+date.getDate(),
        h = date.getHours()>9?date.getHours():'0'+date.getHours(),
        m = date.getMinutes()>9?date.getMinutes():'0'+date.getMinutes(),
        s = date.getSeconds()>9?date.getSeconds():'0'+date.getSeconds();
    return Y+'-'+M+'-'+D+' '+h+':'+m+':'+s;
}

export const downMetod=(source,name)=>{
    axios({
        method: 'get',
        url: source,
        responseType: 'blob'
        }).then(res => {
            fileDownload(res.data,name);
        });
}